const common = require('./common')

const puppeteer = require('puppeteer');

async function recharge(phone , code){
  console.log("start recharge" + phone);
    let text = "";
    const browser = await puppeteer.launch({
      headless: true
    } );
    const page = await browser.newPage();
    await page.goto('https://gsactivity.diditaxi.com.cn/gulfstream/activity/v2/giftpackage/index?g_channel=2ffd919f40806bacd29fd54b1c74ea3f&code='+ code);
    await page.type('#main-phone',phone);
    page.click('#main-btn');
    await common.timeout(10000);
  
    let isSuccess = true;
    let element = await page.$("#receive-desc");
    if(element == null){
      isSuccess = false;
      element = await page.$("#error-title");
    }
    text = await page.evaluate(element => element.textContent, element);
    await browser.close();
    if(isSuccess){
      return {code:"00" ,msg: "充值成功"};
    }else{
      return {code:"01" ,msg: "充值失败"};
    }
}

module.exports={
  recharge
}